import pandas as pd
import utils.python_analysis.kmo_bartlett as kmo_bartlett
import utils.rpy2_analysis.cronbach_alpha_rpy2 as cronbach_alpha
import utils.rpy2_analysis.describe_analysis_rpy2 as describe_analysis_rpy2


# KMO、巴特利特检验
def kmo(file_path, columns):
    # file_path = r'/Users/bytedance/Desktop/Heven/python_project_file/原始数据.sav'
    df = pd.read_spss(file_path)
    # 选择第7到25列数据
    # df = df.iloc[:, 6:26]
    df = df.iloc[:, columns]
    return kmo_bartlett.kmo_bartlett(df)


# alpha
def alpha(file_path, columns):
    df = pd.read_spss(file_path)
    df = df.iloc[:, columns]
    alpha_result = cronbach_alpha.cronbach_alpha(df)
    res = dict()
    res['total'] = alpha_result['total'].to_dict()
    return res


# alpha
def describe(file_path, columns):
    df = pd.read_spss(file_path)
    df = df.iloc[:, columns]
    da_result = describe_analysis_rpy2.describe_analysis(df)
    print(type(da_result[0]))
    res = dict()
    res['b'] = da_result[1].to_dict()
    return res
